package com.lianxian.xindong.commonres.picture.lookImgs;

import android.app.Activity;
import android.content.Intent;

import com.hxb.library.utils.HxbUtils;
import com.lianxian.xindong.commonres.activity.FullImageActivity;
import com.previewlibrary.GPreviewBuilder;
import com.previewlibrary.ZoomMediaLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author :hexingbo
 * @Date :2019/11/22
 * @FileName： ImageViewLookImgsUtils
 * @Describe :
 */
public class LookImgsUtils {

    private List<ImageLookBean> listImg = new ArrayList<>();
    private static LookImgsUtils imgsUtils;

    public static LookImgsUtils init() {
        if (imgsUtils == null) {
            imgsUtils = new LookImgsUtils();
            //初始化图片缩放预览
            ZoomMediaLoader instance = ZoomMediaLoader.getInstance();
            instance.init(new GroupPhotoImageLoader());
        }
        return imgsUtils;
    }


    /**
     * 图片预览
     *
     * @param activity
     * @param urls
     * @param selecteIndex
     */
    public void lookImgs(Activity activity, List<String> urls, int selecteIndex) {
        if (!HxbUtils.isEmpty(urls)) {
            listImg.clear();
            for (String url : urls) {
                listImg.add(new ImageLookBean(url));
            }
            GPreviewBuilder.from(activity)//activity实例必须
                    .setData(listImg)//集合
                    .setCurrentIndex(selecteIndex)
                    .setSingleFling(true)//是否在黑屏区域点击返回
                    .setDrag(false)//是否禁用图片拖拽返回
                    .setType(GPreviewBuilder.IndicatorType.Dot)//指示器类型
                    .start();//启动
        } else {
            HxbUtils.snackbarText("预览图片失败");
        }
    }

    /**
     * 图片预览
     *
     * @param activity
     * @param urls
     * @param selecteIndex
     */
    public void lookImgLooks(Activity activity, List<ImageLookBean> urls, int selecteIndex) {
        if (!HxbUtils.isEmpty(urls)) {

          /*  GPreviewBuilder.from(activity)//activity实例必须
                    .setData(urls)//集合
                    .setCurrentIndex(selecteIndex)
                    .setSingleFling(true)//是否在黑屏区域点击返回
                    .setDrag(false)//是否禁用图片拖拽返回
                    .setType(GPreviewBuilder.IndicatorType.Dot)//指示器类型
                    .start();//启动*/

            ArrayList<String> arrayList = new ArrayList<>();
            for (int i = 0; i < urls.size(); i++) {
                String url = urls.get(i).getUrl();
                arrayList.add(url);
            }
            Intent intent = new Intent(activity, FullImageActivity.class);
            intent.putExtra("data", arrayList);
            intent.putExtra("curentPosion", selecteIndex);
            intent.putExtra("isShow", true);
            //activity.overridePendingTransition(0, 0);
            activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            activity.startActivity(intent);


        } else {
            HxbUtils.snackbarText("预览图片失败");
        }
    }

    /**
     * 图片预览
     *
     * @param activity
     * @param url
     */
    public void lookImgLook(Activity activity, String url) {
        if (!HxbUtils.isEmpty(url)) {

          /*  GPreviewBuilder.from(activity)//activity实例必须
                    .setData(urls)//集合
                    .setCurrentIndex(selecteIndex)
                    .setSingleFling(true)//是否在黑屏区域点击返回
                    .setDrag(false)//是否禁用图片拖拽返回
                    .setType(GPreviewBuilder.IndicatorType.Dot)//指示器类型
                    .start();//启动*/

            ArrayList<String> arrayList = new ArrayList<>();
            arrayList.add(url);
            Intent intent = new Intent(activity, FullImageActivity.class);
            intent.putExtra("data", arrayList);
            intent.putExtra("curentPosion", 0);
            intent.putExtra("isShow", true);
            //activity.overridePendingTransition(0, 0);
            activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            activity.startActivity(intent);


        } else {
            HxbUtils.snackbarText("预览图片失败");
        }
    }

    /**
     * 图片预览
     *
     * @param activity
     * @param url
     */
    public void lookImgs(Activity activity, String url) {
        if (!HxbUtils.isEmpty(url)) {
            listImg.clear();
            listImg.add(new ImageLookBean(url));
            GPreviewBuilder.from(activity)//activity实例必须
                    .setData(listImg)//集合
                    .setCurrentIndex(0)
                    .setSingleFling(true)//是否在黑屏区域点击返回
                    .setDrag(false)//是否禁用图片拖拽返回
                    .setType(GPreviewBuilder.IndicatorType.Dot)//指示器类型
                    .start();//启动
        } else {
            HxbUtils.snackbarText("预览图片失败");
        }
    }
}
